<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>

        /**
         * @param {number} n
         * @return {string}
         */
        var countAndSay = function (n) {
            if (n === 1) return "1";
            const s = countAndSay(n - 1);

            let string = "";
            
            let count = 1;
            let item = s[0];
            for (let i = 1; i < s.length; i++) {
                if (s[i] === item) {
                count++;
                } else {
                string += `${count}${item}`;
                count = 1;
                item = s[i];
                }
            }
            return string+`${count}${item}`;
        };
        console.log(countAndSay(10))
        
    </script>
</body>
</html>